//
//  VisitorLoginView.swift
//  swift新浪微博
//
//  Created by sunchanggui on 15/7/29.
//  Copyright © 2015年 sunchanggui. All rights reserved.
//

import UIKit

protocol VisitorLoginViewDelegate: NSObjectProtocol {
    
    // 点击按钮登录
    func loginVisitorLoginViewDidSeleted();
    
    // 点击按钮注册
    func registerVisitorLoginViewDidSeleted();
    
}

class VisitorLoginView: UIView {

    @IBOutlet weak var smallIcon: UIImageView!
    
    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var messageLabel: UILabel!
    
    weak var delegate: VisitorLoginViewDelegate?
    
    func setupInfo(imageName: String, message: String, isHome: Bool = false) {
        iconView.hidden = !isHome
        if isHome {
            iconView.image = UIImage(named: imageName)
            startAnimation()
        }  else {
            smallIcon.image = UIImage(named: imageName)
        }
        messageLabel.text = message
        
        //isHome ? startAnimation() : stopAnimation()
    }
    
    
    func startAnimation() {
        print(__FUNCTION__)

        let animation = CABasicAnimation(keyPath: "transform.rotation")
        animation.toValue = 2 * M_PI
        animation.duration = 20
        animation.repeatCount = MAXFLOAT
        
        smallIcon.layer.addAnimation(animation, forKey: nil)
    }
//    
//    func stopAnimation() {
//        //print(__FUNCTION__)
//        
//        smallIcon.layer.removeAllAnimations()
//    }
//    
    
    @IBAction func login(sender: UIButton) {
        print("登录")
        
        delegate?.loginVisitorLoginViewDidSeleted()
    }
    
    @IBAction func register(sender: UIButton) {
        print("注册")
        
        delegate?.registerVisitorLoginViewDidSeleted()
    }
    
    
    
}
